package com.next.db;

import io.shardingsphere.api.algorithm.sharding.PreciseShardingValue;
import io.shardingsphere.api.algorithm.sharding.standard.PreciseShardingAlgorithm;

import java.util.Collection;

public class TrainSeatTableShardingAlgorithm implements PreciseShardingAlgorithm<Integer> {

    private final static String PREFIX = "train_seat_";

    private String determineDB(int val) {
        int table = val % 10;
        return PREFIX + (table == 0 ? 10 : table);
    }

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> preciseShardingValue) {
        return determineDB(preciseShardingValue.getValue());
    }
}
